
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Cookies</title>
</head>
<body>
<%
    String id=null;
    String phone=null;
    id =request.getParameter("id");
    phone=request.getParameter("phone");
    Cookie c = new Cookie("id", id);
    Cookie c2=new Cookie("phone",phone);
    c.setMaxAge(60*60*2);
    c2.setMaxAge(60*60*2);
    response.addCookie(c);
    response.addCookie(c2);
    Cookie[] cookies=request.getCookies();
    for (Cookie cooky : cookies) {
        if (cooky.getName().equals("id")) {
            id = cooky.getValue();
        } else if (cooky.getName().equals("phone")) {
            phone = cooky.getValue();
        }
    }

%>
<form action="cookiesIn.jsp">
    ID:<input type="text" name="id" value=<%=id%>>
    Phone:<input type="text" name="phone" value=<%=phone%>>
    <button type="submit" value="提交">提交</button>
</form>
</body>
</html>
